<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Elisa3: I2C Master library</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Elisa3
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Data&#160;Structures</span></a></li>
      <li><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('group__pfleury__ic2master.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="headertitle">
<div class="title">I2C Master library</div>  </div>
</div><!--header-->
<div class="contents">

<p>I2C (TWI) Master Software Library.  
<a href="#details">More...</a></p>
<p>I2C (TWI) Master Software Library. </p>
<p>Basic routines for communicating with I2C slave devices. This single master implementation is limited to one bus master on the I2C bus.</p>
<p>This I2c library is implemented as a compact assembler software implementation of the I2C protocol which runs on any AVR (i2cmaster.S) and as a TWI hardware interface for all AVR with built-in TWI hardware (<a class="el" href="twimaster_8c.html">twimaster.c</a>). Since the API for these two implementations is exactly the same, an application can be linked either against the software I2C implementation or the hardware I2C implementation.</p>
<p>Use 4.7k pull-up resistor on the SDA and SCL pin.</p>
<p>Adapt the SCL and SDA port and pin definitions and eventually the delay routine in the module i2cmaster.S to your target when using the software I2C implementation !</p>
<p>Adjust the CPU clock frequence F_CPU in <a class="el" href="twimaster_8c.html">twimaster.c</a> or in the Makfile when using the TWI hardware implementaion.</p>
<dl class="note"><dt><b>Note:</b></dt><dd>The module i2cmaster.S is based on the Atmel Application Note AVR300, corrected and adapted to GNU assembler and AVR-GCC C call interface. Replaced the incorrect quarter period delays found in AVR300 with half period delays.</dd></dl>
<dl class="author"><dt><b>Author:</b></dt><dd>Peter Fleury <a href="mailto:pfleury@gmx.ch">pfleury@gmx.ch</a> <a href="http://jump.to/fleury">http://jump.to/fleury</a></dd></dl>
<dl class="user"><dt><b>API Usage Example</b></dt><dd>The following code shows typical usage of this library, see example test_i2cmaster.c</dd></dl>
<div class="fragment"><pre class="fragment"><span class="preprocessor"> #include &lt;i2cmaster.h&gt;</span>


<span class="preprocessor"> #define Dev24C02  0xA2      // device address of EEPROM 24C02, see datasheet</span>
<span class="preprocessor"></span>
 <span class="keywordtype">int</span> <a class="code" href="main_8c.html#a840291bc02cba5474a4cb46a9b9566fe">main</a>(<span class="keywordtype">void</span>)
 {
     <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> ret;

     <a class="code" href="twimaster_8c.html#a5730d9445429351b9f750084c5cb5aae" title="initialize the I2C master interace. Need to be called only once">i2c_init</a>();                             <span class="comment">// initialize I2C library</span>

     <span class="comment">// write 0x75 to EEPROM address 5 (Byte Write) </span>
     <a class="code" href="twimaster_8c.html#a0ef0de570e080339e04edb1176807560" title="Issues a start condition and sends address and transfer direction.">i2c_start_wait</a>(Dev24C02+<a class="code" href="twimaster_8h.html#a9536bf85bced4f4e549a82fb18eb6140">I2C_WRITE</a>);     <span class="comment">// set device address and write mode</span>
     <a class="code" href="twimaster_8c.html#add947aade44ed6b7f92265f9dec4a711" title="Send one byte to I2C device.">i2c_write</a>(0x05);                        <span class="comment">// write address = 5</span>
     <a class="code" href="twimaster_8c.html#add947aade44ed6b7f92265f9dec4a711" title="Send one byte to I2C device.">i2c_write</a>(0x75);                        <span class="comment">// write value 0x75 to EEPROM</span>
     <a class="code" href="twimaster_8c.html#ad35d4e4f52ca74b503d5e5e1e0a3f5f3" title="Terminates the data transfer and releases the I2C bus.">i2c_stop</a>();                             <span class="comment">// set stop conditon = release bus</span>


     <span class="comment">// read previously written value back from EEPROM address 5 </span>
     <a class="code" href="twimaster_8c.html#a0ef0de570e080339e04edb1176807560" title="Issues a start condition and sends address and transfer direction.">i2c_start_wait</a>(Dev24C02+<a class="code" href="twimaster_8h.html#a9536bf85bced4f4e549a82fb18eb6140">I2C_WRITE</a>);     <span class="comment">// set device address and write mode</span>

     <a class="code" href="twimaster_8c.html#add947aade44ed6b7f92265f9dec4a711" title="Send one byte to I2C device.">i2c_write</a>(0x05);                        <span class="comment">// write address = 5</span>
     <a class="code" href="twimaster_8c.html#a70c934b61f3c6ba8524104a1d7197d30" title="Issues a repeated start condition and sends address and transfer direction.">i2c_rep_start</a>(Dev24C02+<a class="code" href="twimaster_8h.html#ab5c0fbe837494c5f9130a5914854250d">I2C_READ</a>);       <span class="comment">// set device address and read mode</span>

     ret = <a class="code" href="twimaster_8c.html#ad89e839fc17b05fbb5dd79897c55234e" title="read one byte from the I2C device, read is followed by a stop condition">i2c_readNak</a>();                    <span class="comment">// read one byte from EEPROM</span>
     <a class="code" href="twimaster_8c.html#ad35d4e4f52ca74b503d5e5e1e0a3f5f3" title="Terminates the data transfer and releases the I2C bus.">i2c_stop</a>();

     <span class="keywordflow">for</span>(;;);
 }
</pre></div> </div><!-- contents -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Data Structures</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Typedefs</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

</div>
  <div id="nav-path" class="navpath">
    <ul>

    <li class="footer">Generated on Tue Feb 7 2012 08:44:47 for Elisa3 by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
